package com.prd.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.prd.config.LoginInterceptor;
import com.prd.mapper.EntBudgetSubentryMapper;
import com.prd.model.EntBudgetSubentry;
import com.prd.model.LoginUser;
import com.prd.service.EntBudgetSubentryService;
import com.prd.util.UserInfoUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class EntBudgetSubentryServiceImpl extends ServiceImpl<EntBudgetSubentryMapper, EntBudgetSubentry> implements EntBudgetSubentryService {

    @Autowired
    private EntBudgetSubentryMapper entBudgetSubentryMapper;

    @Override
    public int insertInfo(EntBudgetSubentry entBudgetSubentry) {
        LoginUser loginUser = LoginInterceptor.threadLocal.get();
        BeanUtils.copyProperties(UserInfoUtil.recordInfo(loginUser.getId(), loginUser.getName(), true), entBudgetSubentry);
        return entBudgetSubentryMapper.insert(entBudgetSubentry);
    }

    @Override
    public int updateInfo(EntBudgetSubentry entBudgetSubentry) {
        LoginUser loginUser = LoginInterceptor.threadLocal.get();
        BeanUtils.copyProperties(UserInfoUtil.recordInfo(loginUser.getId(), loginUser.getName(), false), entBudgetSubentry);
        return entBudgetSubentryMapper.updateById(entBudgetSubentry);
    }
}
